<template>
  <div class="ppt-assistant-container">
    <div class="page-header">
      <div class="header-left">
        <h1>PPT助手</h1>
        <p class="subtitle">基于Kimi AI的智能PPT生成工具</p>
      </div>
      <!-- <div class="header-right">
        <el-button type="primary" @click="createNewPPT">
          <el-icon><Plus /></el-icon>新建PPT
        </el-button>
      </div> -->
    </div>

    <!-- <div class="filter-container">
      <el-form :inline="true" :model="filterForm" class="filter-form">
        <el-form-item label="分类">
          <el-select v-model="filterForm.category" placeholder="全部分类" clearable>
            <el-option label="教育" value="education"></el-option>
            <el-option label="商业" value="business"></el-option>
            <el-option label="科技" value="technology"></el-option>
            <el-option label="医疗" value="medical"></el-option>
            <el-option label="营销" value="marketing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="风格">
          <el-select v-model="filterForm.style" placeholder="全部风格" clearable>
            <el-option label="简约" value="minimal"></el-option>
            <el-option label="商务" value="business"></el-option>
            <el-option label="创意" value="creative"></el-option>
            <el-option label="学术" value="academic"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="filterForm.keyword"
            placeholder="搜索PPT标题或内容"
            clearable
            @keyup.enter="handleSearch"
          >
            <template #prefix>
              <el-icon><Search /></el-icon>
            </template>
          </el-input>
        </el-form-item>
      </el-form>
    </div> -->

    <div class="assistant-content">
      <!-- Kimi PPT生成器嵌入区域 -->
      <div class="kimi-embed-container">
        <iframe
          src="https://kimi.moonshot.cn/kimiplus/conpg18t7lagbbsfqksg"
          frameborder="0"
          allowfullscreen
          class="kimi-iframe"
        ></iframe>
      </div>

      <!-- 历史PPT列表 -->
      <!-- <div class="ppt-list">
        <h3 class="list-title">我的历史PPT</h3>

        <el-row :gutter="20">
          <el-col :span="8" v-for="ppt in pptList" :key="ppt.id">
            <el-card class="ppt-card" shadow="hover">
              <div class="card-header">
                <h3 class="ppt-title">{{ ppt.title }}</h3>
                <el-tag :type="getStatusType(ppt.status)" size="small">
                  {{ getStatusText(ppt.status) }}
                </el-tag>
              </div>
              <div class="ppt-thumbnail" @click="previewPPT(ppt.id)">
                <img :src="ppt.thumbnail" alt="PPT缩略图" />
              </div>
              <div class="ppt-meta">
                <span>{{ ppt.category }}</span>
                <span>{{ ppt.pageCount }}页</span>
                <span>更新于 {{ formatDate(ppt.updatedAt) }}</span>
              </div>
              <div class="card-footer">
                <el-button-group>
                  <el-button type="primary" link @click="editPPT(ppt.id)">
                    <el-icon><Edit /></el-icon>编辑
                  </el-button>
                  <el-button type="primary" link @click="downloadPPT(ppt.id)">
                    <el-icon><Download /></el-icon>下载
                  </el-button>
                  <el-dropdown>
                    <el-button type="primary" link>
                      <el-icon><More /></el-icon>更多
                    </el-button>
                    <template #dropdown>
                      <el-dropdown-menu>
                        <el-dropdown-item @click="sharePPT(ppt.id)">
                          <el-icon><Share /></el-icon>分享
                        </el-dropdown-item>
                        <el-dropdown-item @click="duplicatePPT(ppt.id)">
                          <el-icon><CopyDocument /></el-icon>复制
                        </el-dropdown-item>
                        <el-dropdown-item divided @click="deletePPT(ppt.id)">
                          <el-icon><Delete /></el-icon>删除
                        </el-dropdown-item>
                      </el-dropdown-menu>
                    </template>
                  </el-dropdown>
                </el-button-group>
              </div>
            </el-card>
          </el-col>
        </el-row>

        <div v-if="!pptList.length" class="empty-state">
          <el-empty description="暂无历史PPT记录">
            <el-button type="primary" @click="createNewPPT">创建新PPT</el-button>
          </el-empty>
        </div>

        <div class="pagination-container" v-if="pptList.length">
          <el-pagination
            v-model:current-page="currentPage"
            v-model:page-size="pageSize"
            :total="total"
            :page-sizes="[6, 12, 18, 24]"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div> -->
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
  Plus,
  Edit,
  Download,
  More,
  Share,
  CopyDocument,
  Delete,
  Search,
} from '@element-plus/icons-vue'

const router = useRouter()

// 筛选表单
const filterForm = ref({
  category: '',
  style: '',
  keyword: '',
})

// 分页相关
const currentPage = ref(1)
const pageSize = ref(6)
const total = ref(50)

// 模拟数据
const pptList = ref([
  {
    id: '1',
    title: '产品发布会演示文稿',
    category: '商业',
    status: 'completed',
    thumbnail: 'https://via.placeholder.com/300x200?text=PPT+1',
    pageCount: 12,
    updatedAt: '2024-03-15',
  },
  {
    id: '2',
    title: '人工智能技术分享',
    category: '科技',
    status: 'draft',
    thumbnail: 'https://via.placeholder.com/300x200?text=PPT+2',
    pageCount: 8,
    updatedAt: '2024-03-10',
  },
  {
    id: '3',
    title: '年度营销策略规划',
    category: '营销',
    status: 'completed',
    thumbnail: 'https://via.placeholder.com/300x200?text=PPT+3',
    pageCount: 15,
    updatedAt: '2024-03-05',
  },
])

// 获取状态类型
const getStatusType = (status: string): string => {
  const statusMap: Record<string, string> = {
    draft: 'info',
    completed: 'success',
    archived: 'warning',
  }
  return statusMap[status] || 'info'
}

// 获取状态文本
const getStatusText = (status: string): string => {
  const statusMap: Record<string, string> = {
    draft: '草稿',
    completed: '已完成',
    archived: '已归档',
  }
  return statusMap[status] || '未知状态'
}

// 格式化日期
const formatDate = (date: string): string => {
  return new Date(date).toLocaleDateString('zh-CN')
}

// 创建新PPT
const createNewPPT = () => {
  // 这里可以添加创建新PPT的逻辑
  window.open('https://kimi.moonshot.cn/kimiplus/conpg18t7lagbbsfqksg', '_blank')
}

// 搜索
const handleSearch = () => {
  currentPage.value = 1
  // 这里添加搜索逻辑
}

// 编辑PPT
const editPPT = (id: string) => {
  router.push(`/ppt/${id}/edit`)
}

// 预览PPT
const previewPPT = (id: string) => {
  router.push(`/ppt/${id}/preview`)
}

// 下载PPT
const downloadPPT = (id: string) => {
  ElMessage.success('开始下载PPT')
}

// 分享PPT
const sharePPT = (id: string) => {
  ElMessage.info('分享功能开发中')
}

// 复制PPT
const duplicatePPT = (id: string) => {
  ElMessage.success('复制成功')
}

// 删除PPT
const deletePPT = (id: string) => {
  ElMessageBox.confirm('确定要删除这个PPT吗？', '删除确认', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning',
  })
    .then(() => {
      pptList.value = pptList.value.filter((item) => item.id !== id)
      ElMessage.success('删除成功')
    })
    .catch(() => {})
}

// 处理分页
const handleSizeChange = (val: number) => {
  pageSize.value = val
  // 这里添加分页逻辑
}

const handleCurrentChange = (val: number) => {
  currentPage.value = val
  // 这里添加分页逻辑
}
</script>

<style scoped>
.ppt-assistant-container {
  padding: 20px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.page-header h1 {
  margin: 0;
  font-size: 24px;
  color: #303133;
}

.page-header .subtitle {
  margin: 5px 0 0;
  font-size: 14px;
  color: #909399;
}

.filter-container {
  margin-bottom: 20px;
  padding: 20px;
  background-color: #f5f7fa;
  border-radius: 4px;
}

.kimi-embed-container {
  margin-bottom: 30px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.kimi-iframe {
  width: 100%;
  height: 600px;
  border: none;
}

.list-title {
  margin: 20px 0;
  font-size: 18px;
  color: #303133;
  padding-bottom: 10px;
  border-bottom: 1px solid #ebeef5;
}

.ppt-card {
  margin-bottom: 20px;
  transition: all 0.3s;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.ppt-title {
  margin: 0;
  font-size: 16px;
  color: #303133;
}

.ppt-thumbnail {
  margin-bottom: 10px;
  cursor: pointer;
  border-radius: 4px;
  overflow: hidden;
  height: 160px;
  background-color: #f5f7fa;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ppt-thumbnail img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.ppt-meta {
  display: flex;
  gap: 16px;
  color: #909399;
  font-size: 14px;
  margin-bottom: 10px;
}

.card-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #ebeef5;
}

.empty-state {
  padding: 40px 0;
  text-align: center;
}

.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: center;
}
</style>
